<!--  -->
<template>
  <el-dialog v-loading="isLoading" title="创建管理员" :visible.sync="visible">
    <el-form :model="form" :rules="rules" label-position="left">
      <el-form-item label="name" prop="name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="password" prop="password">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item label="roles">
        <el-select v-model="form.roles" prop="roles">
          <el-option label="管理员" value="admin" />
          <el-option label="超级管理员" value="super-admin" />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="httpAddAdmin">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'AddAdminDialog',
  data() {
    return {
      isLoading: false,
      visible: false,
      form: {
        name: '',
        password: '',
        roles: 'admin'
      },
      rules: {
        name: [{ required: true, message: ' ', trigger: 'blur' }],
        password: [{ required: true, message: ' ', trigger: 'blur' }],
        roles: [{ required: true, message: ' ', trigger: 'blur' }]
      }
    }
  },
  methods: {
    show() {
      this.visible = true
    },
    httpAddAdmin() {
      this.isLoading = true
      this.request({
        url: '/auth/add-admin',
        method: 'POST',
        data: this.form
      }).then(res => {
        console.log(res)
      }).finally(() => {
        this.$parent.getRolesList(this.$parent.roles)
        this.isLoading = false
        this.visible = false
      })
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
